home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib25 / _truncdf.cpp < prev    next >
Text File  |  1992-12-12  |  2KB  |  100 lines

  1. | not needed with -__M68881__
  2.  
  3. #ifndef    __M68881__
  4.     .text
  5.     .even
  6.     .globl    __truncdfsf2, ___truncdfsf2
  7.  
  8. __truncdfsf2:
  9. ___truncdfsf2:
  10. # ifdef    sfp004
  11.  
  12. | double float to single float conversion routine
  13. | oflow checking is omitted. The ''881 returns a signed infinity.
  14. |
  15. | Written by M.Ritzert
  16. | 5.10.90
  17. | ritzert@dfg.dbp.de
  18. |
  19.  
  20. | addresses of the 68881 data port. This choice is fastest when much data is
  21. | transferred between the two processors.
  22.  
  23. comm =     -6
  24. resp =    -16
  25. zahl =      0
  26.  
  27. | waiting loop ...
  28. |
  29. | wait:
  30. | ww:    cmpiw    #0x8900,a1@(resp)
  31. |     beq    ww
  32. | is coded directly by
  33. |    .long    0x0c688900, 0xfff067f8
  34.  
  35.     lea    0xfffffa50:w,a0
  36.     movew    #0x5400,a0@(comm)    | load double to  fp0
  37.     cmpiw    #0x8900,a0@(resp)    | check
  38.     movel    a7@(4),a0@        | push arguments
  39.     movel    a7@(8),a0@        |
  40.     movew    #0x6400,a0@(comm)    | result (real) to d0
  41.     .long    0x0c688900, 0xfff067f8
  42.     movel    a0@,d0
  43.     rts
  44.  
  45. # else    sfp004
  46.  
  47. | double float to single float conversion routine
  48. |
  49. | written by Kai-Uwe Bloem (I5110401@dbstu1.bitnet).
  50. | Based on a 80x86 floating point packet from comp.os.minix, written by P.Housel
  51. |
  52. |
  53. | Revision 1.2, kub 01-90 :
  54. | added support for denormalized numbers
  55. |
  56. | Revision 1.1, kub 12-89 :
  57. | Ported over to 68k assembler
  58. |
  59. | Revision 1.0:
  60. | original 8088 code from P.S.Housel
  61.  
  62. BIAS4    =    0x7F-1
  63. BIAS8    =    0x3FF-1
  64.  
  65.     lea    sp@(4),a0    | parameter pointer
  66.     moveml    d2-d5,sp@-    | save regs
  67.     moveml    a0@,d4-d5    | get number
  68.  
  69.     movew    a0@,d0        | extract exponent
  70.     movew    d0,d2        | extract sign
  71.     lsrw    #4,d0
  72.     andw    #0x7ff,d0    | kill sign bit
  73.  
  74.     andl    #0x0fffff,d4    | remove exponent from mantissa
  75.     tstw    d0        | check for zero exponent - no leading "1"
  76.     beq    0f        | for denormalized numbers
  77.     orl    #0x100000,d4    | restore implied leading "1"
  78.     bra    1f
  79. 0:    addw    #1,d0        | "normalize" exponent
  80. 1:
  81.     addw    #BIAS4-BIAS8,d0    | adjust bias
  82.  
  83.     addl    d5,d5        | shift up to realign mantissa for floats
  84.     addxl    d4,d4
  85.     addl    d5,d5
  86.     addxl    d4,d4
  87.     addl    d5,d5
  88.     addxl    d4,d4
  89.  
  90.     movel    d5,d1        | set rounding bits
  91.     roll    #8,d1
  92.     andl    #0x00ffffff,d5    | check to see if sticky bit should be set
  93.     beq    2f
  94.     orb    #1,d1        | set sticky bit
  95. 2:
  96.     jmp    norm_sf        | (leave regs on stack for norm_sf)
  97.  
  98. # endif    sfp004
  99. #endif    __M68881__
  100.